package com.zhang.gulimall.search.controller;

import com.zhang.gulimall.common.exception.BizCodeEnume;
import com.zhang.gulimall.common.to.es.SkuEsModel;
import com.zhang.gulimall.common.utils.R;
import com.zhang.gulimall.search.service.ProductSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search/save")
public class ElasticSearchController {

    @Autowired
    ProductSaveService productSaveService;

    @RequestMapping("/product/up")
    public R up(@RequestBody List<SkuEsModel> skuEsModels) throws IOException {
        boolean b = productSaveService.saveSku(skuEsModels);
        if (!b){
            return R.ok();
        } else {
            return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }
    }
}
